<?php

namespace app\common\model\mysql;

use think\Model;

class SPartnersCategory extends Model
{
    /**
     * 自动生成写入时间
     * @var bool
     */
    protected $autoWriteTimestamp = true;

    /**
     * 查询行业类别数据列表
     * @param $where
     * @param $field
     * @param $limit
     * @param $page
     * @return \think\Paginator
     * @throws \think\db\exception\DbException
     */
    public function getNormalPartnersCategoryList($where, $field,$limit,$page){
        $order = [
            "partners_category_id" =>"asc",
        ];
        $result = $this->where($where)->field($field)->order($order)
            ->paginate([
                'list_rows' => $limit,
                'page' => $page,
            ]);
        return $result;
    }

    public function getNormalPartnersCategoryNotPageList($where, $field){
        $order = [
            "partners_category_id" =>"asc",
        ];
        $result = $this->where($where)->field($field)->order($order)->select();
        return $result;
    }

    public function delPartnersCategoryIds($ids){
        if(empty($ids)){
            return false;
        }
        $where = [
            ['partners_category_id', 'in', $ids],
            ['del_flag', '=', '0']
        ];
        $data = [
            'del_flag'=>'2'
        ];
        $result = $this->where($where)->save($data);
        return $result;
    }

    /**
     * 根据id获取行业类别信息
     * @param $id
     * @return SysDictData|array|false|mixed|Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getPartnersCategoryIdData($id){
        if(empty($id)){
            return false;
        }
        $where = [
            "partners_category_id" =>$id,
        ];
        $result = $this->where($where)->find();
        return $result;
    }

    public function getPartnersCategoryByNameModel($partners_category_name,$partners_category_id){
        if(empty($partners_category_name)){
            return false;
        }
        $where = [
            "partners_category_name" =>$partners_category_name,
            "del_flag"=>'0',
        ];
        if($partners_category_id){
            $result = $this->where("partners_category_id", "<>", $partners_category_id)->where($where)->find();
        }else{
            $result = $this->where($where)->find();
        }
        return $result;
    }
}
